package com.scoy.honeymei.activity.me;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.HttpParams;
import com.scoy.honeymei.R;
import com.scoy.honeymei.activity.home.FilmList0Activity;
import com.scoy.honeymei.adapter.CinemaListAdapter;
import com.scoy.honeymei.adapter.PhoneAdapter;
import com.scoy.honeymei.base.BaseActivity;
import com.scoy.honeymei.bean.CinemaBean;
import com.scoy.honeymei.bean.FilmVipBean;
import com.scoy.honeymei.bean.PhoneBean;
import com.scoy.honeymei.databinding.ActivityServiceBinding;
import com.scoy.honeymei.http.HpCallback;
import com.scoy.honeymei.http.HpGo;
import com.scoy.honeymei.url.ApiCallBack;
import com.scoy.honeymei.url.MeConstant;
import com.scoy.honeymei.url.MyUrl;
import com.scoy.honeymei.utils.GlideImgUtil;
import com.scoy.honeymei.utils.IntentUtil;
import com.scoy.honeymei.utils.LogUtil;
import com.scoy.honeymei.utils.MyUtil;
import com.scoy.honeymei.utils.SPHelper;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @ClassName: ContactActivity$
 * @Description: 联系客服
 * @Author: GaoZhan
 * @CreateDate: 2019/9/11/0011$ 上午 10:33$
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/9/11/0011$ 上午 10:33$
 * @UpdateRemark: 更新内容
 */
public class ContactActivity extends BaseActivity {


    private ContactActivity mContext;
    private PhoneAdapter hAdapter;
    private ActivityServiceBinding binding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityServiceBinding.inflate(getLayoutInflater());

        setContentView(binding.getRoot());
        ButterKnife.bind(this);
        mContext = ContactActivity.this;

        initNormal();

        httpMephone();
    }

    @Override
    public void initNormal() {
        binding.layTop.titleTv.setText(R.string.contactservice);
        MyUtil.setStatusBar(mContext, getWindow(), true, R.color.colorWhite);
        binding.layTop.titleLlt.setPadding(0, MyUtil.getStatusBarHeight(mContext), 0, 0);

        binding.layTop.backIv.setOnClickListener(v -> onBackPressed());


        initRv();
    }


    private void initRv() {

        hAdapter = new PhoneAdapter(mContext);
        binding.asRv.setLayoutManager(new LinearLayoutManager(mContext, RecyclerView.VERTICAL, false));
        binding.asRv.setAdapter(hAdapter);
        hAdapter.setOnOneClick(pos -> {
            PhoneBean mBean = hAdapter.getItem(pos);
            String mobile = mBean.getMobile();
            if (!"".equals(mobile)) {
                IntentUtil.callPhone1(mContext, mBean.getMobile());
            } else {
                MyUtil.mytoast(mContext, "客服电话为空");
            }
        });

    }

    private void httpMephone() {
        HttpParams params = new HttpParams();
        HpGo.newInstance().HttpGo(this, MyUrl.CONTACT_PHONE, params, new ApiCallBack() {
            @Override
            public void onSuccess(String o) {
                List<PhoneBean> mlist = new Gson().fromJson(o, new TypeToken<List<PhoneBean>>() {
                }.getType());
                hAdapter.addData(mlist);
            }

        });

    }
}
